package com.usian.base;

import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.admin.model.common.dtos.PageRequestDto;
import com.usian.admin.model.common.dtos.PageResponseResult;
import com.usian.admin.model.common.dtos.ResponseResult;
import com.usian.admin.model.common.enums.AppHttpCodeEnum;

public class BaseServiceImpl<M extends BaseMapper<T>,T> extends ServiceImpl<M,T> {
   protected ResponseResult paramError=ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
   protected ResponseResult okResult=ResponseResult.errorResult(AppHttpCodeEnum.SUCCESS);
   protected ResponseResult noData=ResponseResult.errorResult(AppHttpCodeEnum.DATA_EXIST);
   public ResponseResult getpageResult(PageRequestDto dto, IPage page, AbstractWrapper wrapper){
      IPage pageResult=page(page,wrapper);
      PageResponseResult result = new PageResponseResult(dto.getPage(), dto.getSize(), (int) pageResult.getTotal());
      result.setData(pageResult.getRecords());
      return result;
   }
}
